/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ProjeteisPanelView.java
 *
 * Created on 07/06/2011, 00:12:16
 */
package view;

import java.awt.BorderLayout;
import java.awt.Canvas;
import monkey.ProjeteisMonkey;
import util.Monkey4Canvas;

/**
 *
 * @author mathyas
 */
public class ProjeteisPanelView extends BasePanelControl {
    
    private ProjeteisMonkey monkey;
    
    private float massa;
    private float pontoX;
    private float pontoY;
    private float velocidadeX;
    private float velocidadeY;
    private float aceleracaoX;
    private float aceleracaoY;

    /** Creates new form ProjeteisPanelView */
    public ProjeteisPanelView() {
        initComponents();
        
        monkey = new ProjeteisMonkey(this);
        Canvas canvas = Monkey4Canvas.parse(monkey);
        jPanelMonkey.setLayout(new BorderLayout());
        jPanelMonkey.add(canvas);
        monkey.startCanvas();
        
        velocidadeX = Float.parseFloat(jTextFieldVx.getText());
        velocidadeY = Float.parseFloat(jTextFieldVy.getText());
        aceleracaoX = Float.parseFloat(jTextFieldAceleracaoX.getText());
        aceleracaoY = Float.parseFloat(jTextFieldAceleracaoY.getText());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroupOpcap = new javax.swing.ButtonGroup();
        jLabelTitulo = new javax.swing.JLabel();
        jPanelMonkey = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabelAceleracao = new javax.swing.JLabel();
        jLabelMS22 = new javax.swing.JLabel();
        jLabelKg = new javax.swing.JLabel();
        jLabelVelocidadeY = new javax.swing.JLabel();
        jTextFieldAceleracaoY = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabelVelocidadeX = new javax.swing.JLabel();
        jTextFieldVy = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jTextFieldAceleracaoX = new javax.swing.JTextField();
        jLabelax = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabelMassa = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabelMS2 = new javax.swing.JLabel();
        jButtonPause = new javax.swing.JButton();
        jLabelPontoX = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jTextFieldVx = new javax.swing.JTextField();
        jLabelVx = new javax.swing.JLabel();
        jButtonMenos1 = new javax.swing.JButton();
        jLabelms1 = new javax.swing.JLabel();
        jLabelVelocIncial = new javax.swing.JLabel();
        jLabelMS = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jTextFieldMassa = new javax.swing.JTextField();
        jButtonMais1 = new javax.swing.JButton();
        jButtonReset = new javax.swing.JButton();
        jLabelPontoY = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jButtonPlay = new javax.swing.JButton();

        jLabelTitulo.setText("Movimento de Projetéis");

        javax.swing.GroupLayout jPanelMonkeyLayout = new javax.swing.GroupLayout(jPanelMonkey);
        jPanelMonkey.setLayout(jPanelMonkeyLayout);
        jPanelMonkeyLayout.setHorizontalGroup(
            jPanelMonkeyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 489, Short.MAX_VALUE)
        );
        jPanelMonkeyLayout.setVerticalGroup(
            jPanelMonkeyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 455, Short.MAX_VALUE)
        );

        jLabel2.setText("ay:");

        jLabelAceleracao.setText("Aceleração:");

        jLabelMS22.setText("m/s²");

        jLabelKg.setText("Kg");

        jLabelVelocidadeY.setText("0");

        jTextFieldAceleracaoY.setText("0");

        jLabel7.setText("Velocidade Y:");

        jLabelVelocidadeX.setText("0");

        jTextFieldVy.setText("0");

        jLabel5.setText("vy:");

        jTextFieldAceleracaoX.setText("0");

        jLabelax.setText("ax:");

        jLabel4.setText("Ponto X:");

        jLabelMassa.setText("Massa:");

        jLabel9.setText("m/s");

        jLabelMS2.setText("m/s²");

        jButtonPause.setText("Pause");
        jButtonPause.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonPauseActionPerformed(evt);
            }
        });

        jLabelPontoX.setText("0");

        jLabel1.setText("Velocidade X:");

        jTextFieldVx.setText("0");

        jLabelVx.setText("vx:");

        jButtonMenos1.setText("-1s");

        jLabelms1.setText("m/s");

        jLabelVelocIncial.setText("Velocidade Incial:");

        jLabelMS.setText("m/s");

        jLabel3.setText("m/s");

        jTextFieldMassa.setText("0");

        jButtonMais1.setText("+1s");

        jButtonReset.setText("Reset");
        jButtonReset.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonResetActionPerformed(evt);
            }
        });

        jLabelPontoY.setText("0");

        jLabel6.setText("Ponto Y:");

        jButtonPlay.setText("Play");
        jButtonPlay.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonPlayActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabelMassa)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldMassa, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabelKg))
                    .addComponent(jLabelVelocIncial)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(14, 14, 14)
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldVy, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabelMS))
                    .addComponent(jLabelAceleracao)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(14, 14, 14)
                        .addComponent(jLabelax)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldAceleracaoX, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabelMS22))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(14, 14, 14)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldAceleracaoY, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabelMS2))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButtonPlay, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButtonPause)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonReset))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButtonMais1, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButtonMenos1, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addGap(6, 6, 6)
                        .addComponent(jLabelPontoX))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addGap(6, 6, 6)
                        .addComponent(jLabelPontoY))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addGap(6, 6, 6)
                        .addComponent(jLabelVelocidadeY)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel9))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(6, 6, 6)
                        .addComponent(jLabelVelocidadeX)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel3))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(7, 7, 7)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabelTitulo)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabelVx)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldVx, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabelms1)))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanelMonkey, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelTitulo)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelMassa)
                    .addComponent(jTextFieldMassa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelKg))
                .addGap(21, 21, 21)
                .addComponent(jLabelVelocIncial)
                .addGap(14, 14, 14)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelms1)
                    .addComponent(jTextFieldVx, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelVx))
                .addGap(17, 17, 17)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelMS)
                    .addComponent(jTextFieldVy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addGap(29, 29, 29)
                .addComponent(jLabelAceleracao)
                .addGap(9, 9, 9)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelMS22)
                    .addComponent(jTextFieldAceleracaoX, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelax))
                .addGap(9, 9, 9)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelMS2)
                    .addComponent(jTextFieldAceleracaoY, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(32, 32, 32)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonPlay)
                    .addComponent(jButtonPause)
                    .addComponent(jButtonReset))
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonMais1)
                    .addComponent(jButtonMenos1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(jLabelPontoX))
                .addGap(6, 6, 6)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addComponent(jLabelPontoY))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabelVelocidadeX)
                        .addComponent(jLabel3)))
                .addGap(6, 6, 6)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabelVelocidadeY)
                        .addComponent(jLabel9)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addComponent(jPanelMonkey, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

private void jButtonPauseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonPauseActionPerformed
    monkey.setMassa(0);
    monkey.setVelocidadeCorpo(0, 0, 0);
    monkey.setAceleracaoCorpo(0, 0, 0);
}//GEN-LAST:event_jButtonPauseActionPerformed

private void jButtonResetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonResetActionPerformed
    monkey.resetCorpo();
}//GEN-LAST:event_jButtonResetActionPerformed

private void jButtonPlayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonPlayActionPerformed
    //implementar validações dos campos
    massa = Float.parseFloat(jTextFieldMassa.getText());
    velocidadeX = Float.parseFloat(jTextFieldVx.getText());
    velocidadeY = Float.parseFloat(jTextFieldVy.getText());
    aceleracaoX = Float.parseFloat(jTextFieldAceleracaoX.getText());
    aceleracaoY = Float.parseFloat(jTextFieldAceleracaoY.getText());
    
    monkey.setMassa(massa);
    monkey.setVelocidadeCorpo(velocidadeX, velocidadeY, 0);
    monkey.setAceleracaoCorpo(aceleracaoX, aceleracaoY, 0);
}//GEN-LAST:event_jButtonPlayActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroupOpcap;
    private javax.swing.JButton jButtonMais1;
    private javax.swing.JButton jButtonMenos1;
    private javax.swing.JButton jButtonPause;
    private javax.swing.JButton jButtonPlay;
    private javax.swing.JButton jButtonReset;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLabel jLabelAceleracao;
    private javax.swing.JLabel jLabelKg;
    private javax.swing.JLabel jLabelMS;
    private javax.swing.JLabel jLabelMS2;
    private javax.swing.JLabel jLabelMS22;
    private javax.swing.JLabel jLabelMassa;
    private javax.swing.JLabel jLabelPontoX;
    private javax.swing.JLabel jLabelPontoY;
    private javax.swing.JLabel jLabelTitulo;
    private javax.swing.JLabel jLabelVelocIncial;
    private javax.swing.JLabel jLabelVelocidadeX;
    private javax.swing.JLabel jLabelVelocidadeY;
    private javax.swing.JLabel jLabelVx;
    private javax.swing.JLabel jLabelax;
    private javax.swing.JLabel jLabelms1;
    private javax.swing.JPanel jPanelMonkey;
    private javax.swing.JTextField jTextFieldAceleracaoX;
    private javax.swing.JTextField jTextFieldAceleracaoY;
    private javax.swing.JTextField jTextFieldMassa;
    private javax.swing.JTextField jTextFieldVx;
    private javax.swing.JTextField jTextFieldVy;
    // End of variables declaration//GEN-END:variables

    @Override
    public void start() {
        monkey.setPauseOnLostFocus(false);
    }

    @Override
    public void pause() {
        monkey.setPauseOnLostFocus(true);
    }

    @Override
    public void destroy() {
        monkey.stop(true);
    }

    /**
     * @return the jLabelPontoX
     */
    public javax.swing.JLabel getjLabelPontoX() {
        return jLabelPontoX;
    }

    /**
     * @param jLabelPontoX the jLabelPontoX to set
     */
    public void setjLabelPontoX(javax.swing.JLabel jLabelPontoX) {
        this.jLabelPontoX = jLabelPontoX;
    }

    /**
     * @return the jLabelPontoY
     */
    public javax.swing.JLabel getjLabelPontoY() {
        return jLabelPontoY;
    }

    /**
     * @param jLabelPontoY the jLabelPontoY to set
     */
    public void setjLabelPontoY(javax.swing.JLabel jLabelPontoY) {
        this.jLabelPontoY = jLabelPontoY;
    }
    
}
